<template>
	<view>
		<view v-if="items.length>0">
			<scroll-view scroll-y="true" style="height: 100vh;">
				<view style="width: 710rpx;margin-left: 20rpx;margin-top: 30rpx;" v-for="(item,i) in items">
					<view style="display: flex;justify-content: space-between;align-items: center;">
						<view>
							<view style="font-size: 32rpx;font-weight: 600;" >{{item.transferTypeName}}</view>
							<view style="font-size: 24rpx;color: #999999;margin-top: 10rpx;">{{item.createTime}}
							</view>
							<view style="font-size: 28rpx;color: #999999;margin-top: 20rpx;">
								<view v-if="item.transferType==4">{{item.paymentChannels=='MP' ? '小程序':'服务号'}}用户{{item.name}}成为推广员</view>
							</view>
						</view>
						<view>
							<view v-if="item.transferTypeName!=='提现'">收益： +<span style="color: red;">{{item.transferMoney}}</span>
							</view>
							<view v-else>-<span style="color: red;">{{item.transferMoney}}</span>
							</view>
						</view>
					</view>
					<view style="width: 100%;height: 1rpx;background-color: #E6E6E6;margin-top: 25rpx;"></view>
				</view>

			</scroll-view>
		</view>
		<view style="width:750rpx;height: 60vh;display: flex;justify-content: center;align-items: center;" v-else>
			<view>
				<u-empty mode="list" icon="info-circle">
				</u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import store from "@/store/index.js"
	var jWeixin
	export default {
		data() {
			return {
				items: []
			}
		},
		onShow() {
			if (uni.getStorageSync('userStatus')) {
				let userStatus = uni.getStorageSync('userStatus')
				this.change(userStatus)
			}else{
				this.cread()
			}
			
		},
		onLoad() {
			
			//#ifdef H5
			this.wxCofing()
			// #endif
		},
		methods: {
			async change(e) {
				console.log(e)
				let mood = e.split('+')
				console.log(mood)
				let res = await this.$request('accounts/edit', {
					userStatus: 2,
					version: mood[1],
					id: mood[2]
				})
				uni.removeStorageSync('userStatus')
				this.cread()
			},
			async wxCofing() {
				jWeixin = require('jweixin-module');
				var uri = window.location.href.split('#')[0]; //获取当前url然后传递给后台获取授权和签名信息  
				let res = await this.$request('wechat/config', {
					url: uri
				}, 'get')
				
				jWeixin.config({
					debug: false,
					appId: res.appId,
					timestamp: res.timestamp,
					nonceStr: res.nonceStr,
					signature: res.signature,
					jsApiList: ["getLocation", "chooseWXPay", "requestMerchantTransfer"]
				})
			},
			async Payment(mood) {
				//#ifdef H5
				if (mood.paymentChannels == 'MP') {
					uni.showToast({
						title: '订单为小程序订单，请前往小程序收款',
						icon: 'none'
					})
					return false
				}
				// #endif
				//#ifdef MP-WEIXIN
				if (mood.paymentChannels == 'H5') {
					uni.showToast({
						title: '订单为服务号订单，请前往服务号收款',
						icon: 'none'
					})
					return false
				}
				// #endif
				// #ifdef MP-WEIXIN
				if (wx.canIUse('requestMerchantTransfer')) {
					wx.requestMerchantTransfer({
						mchId: mood.mchId,
						appId: 'wx86ad7950e07218a5',
						package: mood.packageInfo,
						success: (res) => {
							// res.err_msg将在页面展示成功后返回应用时返回ok，并不代表付款成功
							console.log('success:', res);
							let cont = mood.userStatus + '+' + mood.version + '+' + mood.id
							uni.setStorageSync("userStatus", cont)
						},
						fail: (res) => {
							console.log('fail:', res);
						},
					});
				} else {
					wx.showModal({
						content: '你的微信版本过低，请更新至最新版本。',
						showCancel: false,
					});
				}
				// #endif
				//#ifdef H5
				if (this.$jwx && this.$jwx.isWechat()) { //检查是否是微信环境
					jWeixin.ready(function() {
						jWeixin.checkJsApi({
							jsApiList: ['requestMerchantTransfer'],
							success: function(res) {
								if (res.checkResult['requestMerchantTransfer']) {
									WeixinJSBridge.invoke('requestMerchantTransfer', {
											mchId: mood.mchId,
											appId: 'wx8c726aef4a4b511a',
											package: mood.packageInfo,
										},
										function(res) {
											if (res.err_msg === 'requestMerchantTransfer:ok') {
												// res.err_msg将在页面展示成功后返回应用时返回success，并不代表付款成功
												let cont = mood.userStatus + '+' + mood
													.version + '+' + mood.id
												uni.setStorageSync("userStatus", cont)
											}
										}
									);
								} else {
									alert('你的微信版本过低，请更新至最新版本。');
								}
							}
						});
					});
				}
				// #endif
			},
			async cread() {
				let res = await this.$request("accounts/sumMoneyDetail")
				// console.log(res,11111111111111111111111)
				this.items = res
			}
		}
	}
</script>

<style>
	.btn {
		width: 150rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		color: #fff;
		background-color: #2869FE;
		border-radius: 15rpx;
	}
</style>